﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PizzaSystem
{
    public partial class Home : Form
    {
        public Home()
        {
            InitializeComponent();
        }

        public Home(AppHome app)
        {
            InitializeComponent();
            this.app = app;
        }

        AppHome app;

        SqlDao sqlDao = new SqlDao();

        private void loginButton_Click(object sender, EventArgs e)
        {
            if (id.Text == "" || pass.Text == "")
            {
                warn_label.Text = "请输入账号和密码...";
                return;
            }
            else
            {
                if (u.Checked)
                {
                    Custom custom = sqlDao.userLogin(id.Text, pass.Text);
                    if (custom.C_id>0)
                    {
                        app.openForm(new UserApp(app, custom));
                    }
                    warn_label.Text = "请检查账号或密码...";
                }
                else if(a.Checked)
                {
                   
                    Admin admin = sqlDao.adminLogin(id.Text, pass.Text);
                    if (admin.A_id !="")
                    {
                        app.openForm(new AdminApp(app, admin));
                    }
                    warn_label.Text = "账号或密码不正确...";
                }
                else
                {
                    Vendor vendor = sqlDao.vendorLogin(id.Text, pass.Text);
                    if (vendor.V_id > 0)
                    {
                        app.openForm(new VendorApp(app, vendor));
                    }
                    warn_label.Text = "账号或密码不正确...";
                }
            }
        }

        private void change(object sender, EventArgs e)
        {
            warn_label.Text = "";
        }
    }
}
